package com.yzt.zhuju.network;

import android.text.TextUtils;

import com.yzt.zhuju.BuildConfig;
import com.yzt.zhuju.constants.PreferenceConstant;
import com.yzt.p_base.utils.SharedPreferenceUtil;

/**
 * author : bob
 * date   : 2022/11/29
 * desc   :
 */
public class HttpUrlManager {

    public static void saveHttpUrl(String domain) {
        SharedPreferenceUtil.getInstance().putSystemValue(PreferenceConstant.SYSTEM_HTTP_URL, domain);
        NetLayer.getInstance().changUrl();
    }

    /**
     * 获取app接口请求的url
     */
    public static String getAppHttpUrl() {
        String domain = (String) SharedPreferenceUtil.getInstance().getSystemValue(PreferenceConstant.SYSTEM_HTTP_URL, "");
        if (!TextUtils.isEmpty(domain)) {
            return domain;
        }
        return HttpUrlConfig.RELEASE_URL;
    }

    public static void saveEnvironment(int domain) {
        SharedPreferenceUtil.getInstance().putSystemValue(PreferenceConstant.SYSTEM_ENVIRONMENT, domain);
    }

    /**
     * 获取app接口的环境 ,0 开发环境 ， 1正式环境  2测试环境
     */
    public static int getEnvironment() {
        int domain;
        if(BuildConfig.DEBUG) {
            domain = (Integer) SharedPreferenceUtil.getInstance().getSystemValue(PreferenceConstant.SYSTEM_ENVIRONMENT, 2);
        } else {
            domain = 0;
        }
        return domain;
    }
}
